<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('广告管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                           <input type="hidden" id="platform" name="platform" th:value="${platform}"/>
                            <li>
                                <p>应用ID：</p>
                                <select id="appId" name="appId" th:with="type=${@dict.getType('kkad_app_id')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="kkad:advertising:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="kkad:advertising:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="kkad:advertising:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('kkad:advertising:edit')}]];
        var removeFlag = [[${@permission.hasPermi('kkad:advertising:remove')}]];
        var statusDatas = [[${@dict.getType('common_status')}]];
        var billingTypeDatas = [[${@dict.getType('kkad_billing_type')}]];
        var platformDatas = [[${@dict.getType('common_platform')}]];
        var targetTypeDatas = [[${@dict.getType('kkad_target_type')}]];
        var testDatas = [[${@dict.getType('common_support')}]];
        var prefix = ctx + "kkad/advertising";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "广告管理",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: true
                },
                {
                    field : 'placeCode', 
                    title : '广告位',
                    formatter: function(value, row, index) {
                    	return row.place.remark
                    }
                },
                {
                    field : 'billingType', 
                    title : '计费类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(billingTypeDatas, value);
                    }
                },
                {
                    field : 'goal', 
                    title : '目标'
                },
                {
                    field : 'sequence', 
                    title : '序号'
                },
                {
                    field : 'imgUri', 
                    title : '图片',
                    formatter: function(value, row, index) {
                    	let width = row.place.width / 8
                    	let height = row.place.height / 8
                        return "<img src='" + value + "' width=" + width + " height=" + height + "/>" ;
                    }
                },
                {
                    field : 'status', 
                    title : '启用',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                      	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                      	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'test', 
                    title : '是否测试',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                     	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                     	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'targetUrl', 
                    title : '跳转URL',
                    formatter: function(value, row, index) {
                        if(value){
                        	return "<a href='" + value + "' target='_blank' title='" + value + "'>点击</a>";
                        }else{
                        	return ''
                        }
                    }
                },
                {
                    field : 'targetType', 
                    title : '跳转类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(targetTypeDatas, value);
                    }
                },
                {
                    field : 'effectStart', 
                    title : '上线时间'
                },
                {
                    field : 'effectEnd', 
                    title : '下线时间'
                },
                {
                    field : 'content', 
                    title : '文字描述'
                },
                {
                    field : 'remark', 
                    title : '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        

        function add(){
        	 var appId = $("#appId option:selected").val();
        	 var platform = $("#platform").val();
        	 $.operate.add(appId + ":" + platform);
        }
        
    </script>
</body>
</html>